package com.szholly.plug.safe.core;

import java.util.HashMap;
import java.util.List;

import com.szholly.utils.cache.CacheFactory;
import com.szholly.utils.cache.data.IMedataCache;
import com.szholly.data.general.RowBase;

/**
 * 定义数据安全类集中缓存处理类
 */
public class SafeCache {

	/**
	 * 角色数据权限缓存键
	 */
	static final String RoleSqlMapCacheKey = "RoleSqlMapCacheKey";

	/**
	 * 角色委托缓存键
	 */
	static final String RoleWTCacheCacheKey = "RoleWTCacheCacheKey";

	/**
	 * 功能缓存键
	 */
	static final String FunctionCacheCacheKey = "FunctionCacheCacheKey";

	/**
	 * 角色功能缓存键
	 */
	static final String RoleFunctionCacheCacheKey = "RoleFunctionCacheCacheKey";
	
	public static void clearCache(){
		IMedataCache medataCache = CacheFactory.getMedataCache();
		medataCache.Remove(FunctionCacheCacheKey);
		medataCache.Remove(RoleFunctionCacheCacheKey);
		medataCache.Remove(RoleSqlMapCacheKey);
		medataCache.Remove(RoleWTCacheCacheKey);
	}

	/**
	 * 获取角色数据权限
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static HashMap<String, HashMap<String, String>> getRoleSqlCache() {
		IMedataCache medataCache = CacheFactory.getMedataCache();
		if (!medataCache.HashKey(RoleSqlMapCacheKey)) {
			return null;
		}
		return (HashMap<String, HashMap<String, String>>) medataCache
				.Get(RoleSqlMapCacheKey);
	}

	/**
	 * 设置角色数据权限
	 * 
	 * @param value
	 */
	public static void setRoleSqlCache(
			HashMap<String, HashMap<String, String>> value) {
		IMedataCache medataCache = CacheFactory.getMedataCache();
		medataCache.Put(RoleSqlMapCacheKey, value);
	}

	/**
	 * 获取权限委托数据权限
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static HashMap<String, List<String>> getRoleWTCache() {
		IMedataCache medataCache = CacheFactory.getMedataCache();
		if (!medataCache.HashKey(RoleWTCacheCacheKey)) {
			return null;
		}
		return (HashMap<String, List<String>>) medataCache
				.Get(RoleWTCacheCacheKey);
	}

	/**
	 * 设置权限委托数据权限
	 * 
	 * @param value
	 */
	public static void setRoleWTCache(HashMap<String, List<String>> value) {
		IMedataCache medataCache = CacheFactory.getMedataCache();
		medataCache.Put(RoleWTCacheCacheKey, value);
	}

	/**
	 * 获取功能权限数据
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static HashMap<String, RowBase> getFunctionCache() {
		IMedataCache medataCache = CacheFactory.getMedataCache();
		if (!medataCache.HashKey(FunctionCacheCacheKey)) {
			return null;
		}
		return (HashMap<String, RowBase>) medataCache
				.Get(FunctionCacheCacheKey);
	}

	/**
	 * 设置功能权限数据
	 * 
	 * @param value
	 */
	public static void setFunctionCache(HashMap<String, RowBase> value) {
		IMedataCache medataCache = CacheFactory.getMedataCache();
		medataCache.Put(FunctionCacheCacheKey, value);
	}

	/**
	 * 获取角色功能权限数据
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static HashMap<String, List<RowBase>> getRoleFunctionCache() {
		IMedataCache medataCache = CacheFactory.getMedataCache();
		if (!medataCache.HashKey(RoleFunctionCacheCacheKey)) {
			return null;
		}
		return (HashMap<String, List<RowBase>>) medataCache
				.Get(RoleFunctionCacheCacheKey);
	}

	/**
	 * 设置角色功能权限数据
	 * 
	 * @param value
	 */
	public static void setRoleFunctionCache(HashMap<String, List<RowBase>> value) {
		IMedataCache medataCache = CacheFactory.getMedataCache();
		medataCache.Put(RoleFunctionCacheCacheKey, value);
	}
}